<%-- 
    Document   : addEvent
    Created on : 13-08-2014, 22:43:25
    Author     : NGOCLINH-PC
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Data.Category"%>
<%@page import="java.util.ArrayList"%>
<%@page import="Data.Event"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<script  language="javascript" type="text/javascript">
    function ClickMe() {
        var url = document.getElementById("fImages").value;
        document.getElementById("txturlanh").value = url;
    }
    function CheckDate() {
        var deadline = document.getElementById("datepicker1").value;
        var timeEvent = document.getElementById("datepicker").value;
        if (deadline >= timeEvent)
        {
            alert("Deadline must be less than the TimeEvent!");
            document.getElementById("datepicker").value = '';
        }
    }
    function checkcurrent() {
        var deadline = document.getElementById("datepicker1").value;
        var d = new Date();
        var date = d.format("yyyy-MM-dd");
        if (deadline < date) {
            alert("Deadline must be greater than the current date!");
            document.getElementById("datepicker1").value = '';
        }
    }



</script>
<div class="tablesanpham">


    <%
        if (request.getParameter("EeventID") != null) {
            out.print("<form action='../UpdateEvent' method='post'  name='form1' enctype='multipart/form-data'>");
            out.print("<h2 style='padding: 10px; color: #999;'>Management Event</h2>");
            out.print("<hr />");
            out.print(" <table width='100%' border='0' cellspacing='14' cellpadding='14'>");

            Event ct = new Event();
            int eventID = Integer.parseInt(request.getParameter("EeventID"));
            ArrayList<Event> a = ct.ESelectByID(eventID);
            if (a.size() > 0) {
                for (int i = 0; i < a.size(); i++) {
                    Event event = a.get(i);

                    out.print("<input type='hidden' name='txtEventID' id='txtEventID' value='" + event.getEventID() + "' />");

    %>

    <tr>
        <td>Category:</td>
        <td><select name="txtCategory">
                <%
                    String str = "";
                    Category r = new Category();
                     ArrayList<Category> ar = r.CselectbyQuery(" AND Status=1");
                    for (int j = 0; j < ar.size(); j++) {
                        Category rol = ar.get(j);

                        if (event.CategoryID() == rol.getCategoryID()) {
                            str += "<option value='" + rol.getCategoryID() + "' selected='selected'>" + rol.getCategoryName() + "</option>";
                        } else {
                            str += "<option value='" + rol.getCategoryID() + "'>" + rol.getCategoryName() + "</option>";
                        }
                    }
                    out.print(str);
                %>
            </select></td>
    </tr>
    <tr>
        <td>Event Name:</td>
        <td>
            <% out.print("<input name='txtEventname' required type='text' id='txtEventname' size='50' value='" + event.getEventName() + "'>");%>
        </td>
    </tr>
    <tr>
        <td>Speakers</td>
        <td><label for="txtSpeakers"></label>
            <% out.print("<input type='text' name='txtSpeakers' id='txtSpeakers' value='" + event.getSpeakers() + "'/>");%>
        </td>
    </tr>
    <tr>
        <td>Address:</td>
        <td><label for="txtAddress"></label>
            <% out.print("<input type='text' name='txtAddress' id='txtAddress' value='" + event.getAddress() + "' />");%>
        </td>
    </tr>
    <tr>
        <td>Description:</td>
        <td><label for="txtDescription"></label>
            <% out.print("<textarea name='txtDescription' id='txtDescription' cols='45' rows='5'>" + event.getDescription() + "</textarea>");%>
        </td>
    </tr>
    <tr>
        <td>Content:</td>
        <td><label for="txtContent"></label>
            <% out.print("<textarea name='txtContent' class='ckeditor' id='txtContent' cols='45' rows='5'>" + event.getContents() + "</textarea>");%>
        </td>
    </tr>
    <tr>
        <td>Price:</td>
        <td><label for="txtPrice"></label>
            <% out.print("<input type='number' name='txtPrice' id='txtPrice' value='" + event.getPrice() + "'/>");%>
        </td>
    </tr>
    <tr>
        <td>Deadline:</td>
        <td><label for="txtDeadline"></label>
            <% out.print("<input type='date' name='txtDeadline' id='datepicker1' value='" + event.getDeadline() + "'/>");%>
        </td>
    </tr>
    <tr>
        <td>Time Event:</td>
        <td><label for="txtTimeEvent"></label>
            <% out.print("<input type='date' name='txtTimeEvent' onchange='CheckDate();' id='datepicker' value='" + event.getTimeEvent() + "'/>");%>
        </td>
    </tr>

    <tr>
        <td>Images: </td>
        <td>
            <% out.print("<img src='../uploads/" + event.getImages() + "' align='' width='200' height='150'  />");%><br />
            <% out.print("<input type='hidden' name='txturlanh' id='txturlanh' value='" + event.getImages() + "'/>");%>
            <% out.print("<input type='file' name='fImages'  onchange='ClickMe()' id='fImages' />");%>
        </td> 
    </tr>
    <tr>
        <td>Status:</td>
        <td> <%
            if (event.getStatus() == 1) {
                out.print("<input type='radio' name='radio1' id='rdtrangthai' value='1' checked />Show");
                out.print("<input type='radio' name='radio1' id='rdtrangthai' value='0' />Hidden");
            } else {
                out.print("<input type='radio' name='radio1' id='rdtrangthai' value='1' />Show");
                out.print("<input type='radio' name='radio1' id='rdtrangthai' value='0' checked />Hidden");
            }

            %>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input name="btnaction" type="submit" id="btnaction" value="Submit"></td>
    </tr>
    <%
            }

            out.print("</table>");
            out.print("</form>");
        }
    } else {
    %>
    <form action="../Event" method="post"  name="form1" enctype="multipart/form-data">
        <h2 style="padding: 10px; color: #999;">Management Event</h2>
        <hr />
        <table width="100%" border="0" cellspacing="14" cellpadding="14">
            <tr>
                <td>Category:</td>
                <td><select name="txtCategory">
                        <%
                            String str = "";
                            Category r = new Category();
                            ArrayList<Category> ar = r.CselectbyQuery(" AND Status=1");
                            for (int j = 0; j < ar.size(); j++) {
                                Category rol = ar.get(j);
                                str += "<option value='" + rol.getCategoryID() + "'>" + rol.getCategoryName() + "</option>";
                            }
                            out.print(str);
                        %>
                    </select></td>
            </tr>
            <tr>
                <td>Event Name:</td>
                <td><input name="txtEventname" required type="text" id="txtEventname" size="50" value=""></td>
            </tr>
            <tr>
                <td>Speakers</td>
                <td><label for="txtSpeakers"></label>
                    <input type="text" name="txtSpeakers" required  id="txtSpeakers" value=""/></td>
            </tr>
            <tr>
                <td>Address:</td>
                <td><label for="txtAddress"></label>
                    <input type="text" name="txtAddress" required id="txtAddress" value=""/></td>
            </tr>
            <tr>
                <td>Description:</td>
                <td><label for="txtDescription"></label>
                    <textarea name="txtDescription" id="txtDescription"  required cols="45" rows="5"></textarea></td>
            </tr>
            <tr>
                <td>Content:</td>
                <td><label for="txtContent"></label>
                    <textarea name="txtContent" id="txtContent" class='ckeditor' required cols="45" rows="5"></textarea></td>
            </tr>
            <tr>
                <td>Price:</td>
                <td><label for="txtPrice"></label>
                    <input type="number" name="txtPrice" id="txtPrice" value=""/></td>

            </tr>

            <tr>
                <td>Deadline:</td>
                <td><label for="txtDeadline"></label>
                    <input type="date" name="txtDeadline" required id='datepicker1' onchange="checkcurrent();" value=""/></td>
            </tr>
            <tr>
                <td>Time Event:</td>
                <td><label for="txtTimeEvent"></label>
                    <input type="date" name="txtTimeEvent" required id='datepicker' onchange="CheckDate();" value=""/>
                    <input type="hidden" name="inst"  value="df"/>
                </td>
            </tr>
            <tr>
                <td>Images: </td>
                <td>

                    <input type="file"  name="fImages" required id="fImages"  />  </td>
            </tr>
            <tr>
                <td>Status:</td>
                <td><input type="radio" name="radio1"  id="rdtrangthai" value="1"  />
                    Show 
                    <input type="radio" name="radio1" id="rdtrangthai" value="0"  checked />
                    Hidden</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input name="btnaction" type="submit" id="btnaction" value="Submit"></td>
            </tr>
            <%}%>
        </table>
    </form>
</div>
